<?php
namespace Zeke\Io\Loop;
use Zeke\Contracts\Io\Loop\LoopContract;

/**
 * The `Factory` class exists as a convenient way to pick the best available event loop implementation.
 */
final class Factory
{
    /**
     * Creates a new event loop instance
     *
     * ```php
     * $loop = React\EventLoop\Factory::create();
     * ```
     *
     * This method always returns an instance implementing `LoopInterface`,
     * the actual event loop implementation is an implementation detail.
     *
     * This method should usually only be called once at the beginning of the program.
     *
     * @return LoopContract
     */
    public static function create()
    {

        if (\class_exists('EventBase', false)) {
            return new ExtEvent();
        } elseif (\function_exists('event_base_new') && \PHP_VERSION_ID < 70000) {
            // only use ext-libevent on PHP < 7 for now
            return new Libevent();
        }
        return new Select();
        // @codeCoverageIgnoreEnd
    }
}